/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonybeans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author 4410s
 */
@Stateless
public class Manger_Registion implements Manger_RegistionLocal {
Connection conn;
    ResultSet rs = null;
    @Override
    public HashMap Select_allRegistion() {
         HashMap hmdata = new HashMap();
    try {
        
        ConnectDB conDB = new ConnectDB();
           conn = conDB.getConnection();
           String strSql = "SELECT * FROM Registration ";

           PreparedStatement pstmt = conn.prepareStatement(strSql);
           rs = pstmt.executeQuery();
           while (rs.next()) {
               HashMap hm = new HashMap();
               hm.put("id_registration", rs.getInt("id_registration"));
               hm.put("id_charges", rs.getInt("id_charges"));
               hm.put("username", rs.getString("username").trim());
               hm.put("date_registration", rs.getTimestamp("date_registration"));
                hm.put("card_types", rs.getString("card_types").trim());
               hm.put("card_number", rs.getString("card_number").trim());
               hm.put("status", rs.getString("status").trim());
               hm.put("username_admin", rs.getString("username_admin").trim());
               hmdata.put(rs.getInt("id_registration"),hm);
           }
       
    } catch (SQLException ex) {
        Logger.getLogger(Manger_Registion.class.getName()).log(Level.SEVERE, null, ex);
    }
     return hmdata ;
    }
Connection con;
    ResultSet rss = null;
    @Override
    public ResultSet Select_ById(int id_registration) {
    try {
        ConnectDB conDB = new ConnectDB();
          con= conDB.getConnection();
          String strSql = "SELECT * FROM Registration where id_registration=? ";

          PreparedStatement pstmt = con.prepareStatement(strSql);
          pstmt.setInt(1, id_registration);
          rss = pstmt.executeQuery();
       
    } catch (SQLException ex) {
        Logger.getLogger(Manger_Registion.class.getName()).log(Level.SEVERE, null, ex);
    }
    return rss;
    }
     Connection con1;
    ResultSet rs1 = null;
    boolean flag = false;
    @Override
    public Boolean Update_Registion( String status,int id_registration) {
    try {
        ConnectDB conDB = new ConnectDB();
           conn = conDB.getConnection();
           String strSql = " Update Registration set status=? where id_registration= ? ";
           PreparedStatement pstmt = conn.prepareCall(strSql);
          
           
            
          
            pstmt.setString(1,status);
           
           
           

           pstmt.setInt(2,id_registration);

           int count;
           count = pstmt.executeUpdate();
           if (count > 0) {
               flag = true;
           } else {
               flag = false;
           }
      
    } catch (SQLException ex) {
        Logger.getLogger(Manger_Registion.class.getName()).log(Level.SEVERE, null, ex);
    }
    return flag;
    }

  

}
